﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lidgren.Network;
public class NetworkSyncManager :SingletonMono<NetworkSyncManager>
{
    public List<NetWorkSyncAgent> allSyncObject = new List<NetWorkSyncAgent>();

    public List<NetTankActor> allSyncActor = new List<NetTankActor>();
    public void OnHandleSyncMsg(NetIncomingMessage msg)
    {
        msg.Position = 0;
        var netConst = msg.ReadByte();
        switch(netConst)
        {
            case NetConst.OnObjectUpdate:
                var id = msg.ReadInt32();
                var syncObj = allSyncObject.Find(x => x.SyncId == id);
                if (syncObj != null)
                    syncObj.OnHandlerSyncPackage(msg);
                break;
            case NetConst.OnPlayerShot:
                var actorGuid = msg.ReadString();
                var syncTank = allSyncActor.Find(x => x.ActorInfo.actorGUID == actorGuid);
                syncTank.OnHandleShoot(msg);
                break;
        }
    }
    public void AddSyncObject(NetWorkSyncAgent syncObj)
    {
        this.allSyncObject.Add(syncObj);
    }

    public void RemoveSyncObject(NetWorkSyncAgent syncObj)
    {
        this.allSyncObject.Remove(syncObj);
    }

    public void AddSyncActor(NetTankActor actor)
    {
        this.allSyncActor.Add(actor);
    }

    public void RemoveSyncActor(NetTankActor actor)
    {
        this.allSyncActor.Remove(actor);
    }
}

